<?php if (!defined('THINK_PATH')) exit();?><style type="text/css">
    .add_label {
        display: -moz-inline-box;
        display: inline-block;
        width: 60px;
        text-align: right;
    }

    #dd div {
        padding-right: 10px;
        padding-bottom: 10px;
    }

    .add_table {
        width: 100%;
    }

    .add_table th {
        width: 140px;
        background-color: #E0ECFF;
        padding: 8px 0 8px 0;
        border-right: solid 1px #95B8E7;
        border-bottom: solid 1px #95B8E7;
    }

    .add_table td {
        border-bottom: solid 1px #95B8E7;
    }

    .add_table tr {
        border: solid 1px #95B8E7;
    }

    .inline {
        display: inline;
    }

    .row_container {
        padding: 8px 5px 5px 5px;
    }
    #syfz-dg{
        width: 100%;
        height: 300px;
    }
    .ggdtitle{
        font-size: 16px;
        text-align: center;
        font-weight: bold;
        padding: 10px;
        color: #0f2d5f;
        border-bottom: 1px solid #95b9e7;
    }
</style>

<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'north',title:'',split:false,border:false" style="height:30px;">
        <div style="background-color: #E0ECFF;">
            <table>
                <tr>
                    <td>
                        <a href="#"  class="easyui-linkbutton" onclick='submit_lsggd()'
                           data-options="iconCls:'icon-ok',plain:true">保存</a>
                        <a href="#"  class="easyui-linkbutton" onclick='publish_lsggd()'
                           data-options="iconCls:'icon-ok',plain:true">发布</a>

                        <a href="#"  class="easyui-linkbutton" onclick='go_back_lsggd()'
                           data-options="iconCls:'icon-back',plain:true">返回</a>



                        <!--<a href="#"  class="easyui-linkbutton" onclick='testtt()'-->
                        <!--data-options="iconCls:'icon-back',plain:true">测试</a>-->

                    </td>
                </tr>
            </table>
        </div>

    </div>
    <div  data-options="region:'center',border:false,title:''" style="padding:5px;">
        <div class="ggdtitle">
            添加工艺临时更改单
        </div>
        <form id="add_lsggd_form" name="myform" enctype="multipart/form-data" method="post">
            <table class="add_table">



                <tr>
                    <td>
                        <div class="row_container">
                            <!--<table id="rehcx"></table>-->
                            <div class="inline">
                                <span class="add_label">关联：</span>
                                <input id="add_rwh" class="easyui-combogrid"
                                       data-options="editable:false,required:false,required:true" name="rwh[]"
                                       style="width:550px;" value='<?php echo ($data["ffdw"]); ?>'/>

                            </div>

                        </div>


                    </td>
                </tr>
                <!--<tr>-->
                    <!--<td>-->
                        <!--<div class="row_container">-->
                            <!--&lt;!&ndash;<table id="rehcx"></table>&ndash;&gt;-->
                            <!--<div class="inline">-->
                                <!--<span class="add_label">文件名称：</span>-->
                                <!--<input id="ggdtitle" class="easyui-textbox"  name="title" title data-options="iconCls:''" style="width:550px" value='<?php echo ($data["title"]); ?>'/>-->

                            <!--</div>-->

                        <!--</div>-->


                    <!--</td>-->
                <!--</tr>-->
                <tr>
                    <td>
                        <div class="row_container">
                            <!--<table id="rehcx"></table>-->
                            <div class="inline">
                                <span class="add_label"></span>

                                <textarea id="add_rwh_show"  class="easyui-textbox"
                                       data-options="iconCls:'',multiline:true,editable:true,required:false,prompt:''"
                                       style="width:550px;height:80px;"/>


                            </div>

                        </div>


                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="row_container">

                            <div class="inline">
                                <span class="add_label">说明：</span>
                                <input id="add_title" name="sm" class="easyui-textbox"
                                       data-options="iconCls:'',multiline:true,editable:true,required:false,prompt:'对更改单的文字性说明，非必填项……'"
                                       style="width:550px;height:60px;" value='<?php echo ($data["sm"]); ?>'/>
                            </div>

                        </div>


                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="row_container">
                            <div class="inline">
                                <span class="add_label">更改原因：</span>
                                <input id="lsggd_reason" class="easyui-combobox" name="reason"
                                       data-options="valueField:'value',editable:false,textField:'text',url:'/solve/index.php/Home/Lsggd/ggyy',panelHeight:'auto',required:true,multiple:false"
                                       style="width:200px;" value='<?php echo ($data["reason"]); ?>'>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>

                    <td>
                        <div class="row_container">
                            <div class="inline">
                                <span class="add_label">增加件：</span>
                                <div id="lsggd_addPart"></div>
                            </div>

                        </div>
                    </td>
                </tr>
                <tr>

                    <td>
                        <div class="row_container">
                            <div class="inline">
                                <span class="add_label">减少件：</span>
                                <div id="lsggd_delPart"></div>
                            </div>

                        </div>
                    </td>
                </tr>
                <tr>
                    <!--Public/Uploads/ueditor/-->

                    <td>
                        <div class="row_container">
                            <div class="inline">
                                <span class="add_label">增加减少说明：</span>
                                <!--<textarea id="container_add" name="part_sm"></textarea>-->
                                <input id="container_add" name="part_sm" class="easyui-textbox"
                                       data-options="iconCls:'',multiline:true,editable:true,required:false,prompt:'对增加减少件的说明，非必填项……'"
                                       style="width:550px;height:60px;" value='<?php echo ($data["part_sm"]); ?>'/>

                            </div>

                        </div>
                    </td>
                </tr>


                <tr>
                    <td>
                        <div class="row_container">

                            <div class="inline">
                                <span class="add_label">附件:</span>
                                <input  name="fjs[]" id="xy_url" style="width:550px;"  class="easyui-filebox" data-options="multiple:'true',buttonText:'上传附件',buttonIcon:'icon-standard-application-edit',accept:'application/msword,image/*,application/vnd.ms-excel,application/pdf'">
                            </div>

                        </div>

                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="row_container">

                            <div class="inline">
                                <span class="add_label">发放单位:</span>

                                <input class="easyui-combobox" name="ffdw[]"
                                       data-options="valueField:'value',textField:'text',editable:false,url:'/solve/index.php/Home/Lsggd/ffdw',panelHeight:'auto',required:true,multiple:'true'"
                                       style="width:550px;" value='<?php echo ($data["ffdw"]); ?>'>
                            </div>

                        </div>

                    </td>
                </tr>

                <tr>
                    <td>
                        <div class="row_container">
                            <div class="inline">
                                <span class="add_label">校对:</span>
                                <input id="add_s1" class="easyui-combobox" name="jd"
                                       data-options="valueField:'value',textField:'text',url:'/solve/index.php/Admin/Public/user1',panelHeight:'auto',required:true"
                                       style="width:100px;" value='<?php echo ($data["s1id"]); ?>'/>
                            </div>

                            <div class="inline">
                                <span class="add_label">审核：</span>
                                <input id="add_s2" class="easyui-combobox" name="sh"
                                       data-options="valueField:'value',textField:'text',url:'/solve/index.php/Admin/Public/zhuguan',panelHeight:'auto',required:true"
                                       style="width:100px;" value='<?php echo ($data["s2id"]); ?>'/>
                            </div>
                            <div class="inline">
                                <span class="add_label">批准：</span>
                                <input id="add_s3" class="easyui-combobox" name="pz"
                                       data-options="valueField:'value',textField:'text',url:'/solve/index.php/Admin/Public/buzhang',panelHeight:'auto',required:true"
                                       style="width:100px;" value='<?php echo ($data["s3id"]); ?>'/>
                            </div>


                        </div>

                    </td>
                </tr>

            </table>

            <input id="ggd_title" type="hidden" name="title"  value=<?php echo ($data['title']); ?>>
            <input id="ggd_header" type="hidden" name="header"  value=<?php echo ($data['header']); ?>>



            <input type="hidden" name="author" id="userid" value=<?php echo ($_SESSION['uid']); ?>>
            <input type="hidden" name="nickname" id="nickname" value=<?php echo ($_SESSION['unickname']); ?>>

        </form>
    </div>
</div>










<div id="myToolbar">
    <!--<input type="text" id="txtLoginName" name="rwh" style="width: 220px;"-->
    <!--class="easyui-textbox" />-->
    <span class="textbox" style="width: 300px; height: 20px;">

        <input type="text" name="rwh"
     class="textbox-text"
     autocomplete="off" placeholder=""
     style="margin-left: 0px; margin-right: 0px; padding-top: 0px; padding-bottom: 0px; height: 20px; line-height: 20px; width: 350px;"
     title="">

    </span>
    <a onclick="Search();" href="javascript:void(0)" class="l-btn l-btn-small l-btn-plain">
                    <span class="l-btn-left l-btn-icon-left"><span class="l-btn-text" title="搜索">搜索</span><span
                            class="l-btn-icon icon-search"> </span></span></a>
    <a onclick="loadAgain();" href="javascript:void(0)" class="l-btn l-btn-small l-btn-plain">
                    <span class="l-btn-left l-btn-icon-left"><span class="l-btn-text">刷新</span><span
                            class="l-btn-icon icon-reload"> </span></span></a>
</div>

<script>


    // lsggd_delPart

    var addContainer = document.getElementById('lsggd_addPart');
    var delContainer = document.getElementById('lsggd_delPart');


    var data=[
        {'gw':'','ljh':'','mc':'','sl':'','kc':'','bz':''},
        {'gw':'','ljh':'','mc':'','sl':'','kc':'','bz':''},
        {'gw':'','ljh':'','mc':'','sl':'','kc':'','bz':''},
        {'gw':'','ljh':'','mc':'','sl':'','kc':'','bz':''},
        {'gw':'','ljh':'','mc':'','sl':'','kc':'','bz':''},
        {'gw':'','ljh':'','mc':'','sl':'','kc':'','bz':''}

    ];
    var data1=[
        {'gw':'','ljh':'','mc':'','sl':'','kc':'','bz':''},
        {'gw':'','ljh':'','mc':'','sl':'','kc':'','bz':''},
        {'gw':'','ljh':'','mc':'','sl':'','kc':'','bz':''},
        {'gw':'','ljh':'','mc':'','sl':'','kc':'','bz':''},
        {'gw':'','ljh':'','mc':'','sl':'','kc':'','bz':''},
        {'gw':'','ljh':'','mc':'','sl':'','kc':'','bz':''}

    ];
    var hotSettings = {
        data:data,
        columns: [
            {
                data: 'gw',
                type: 'text',
                width: 20
            },
            {
                data: 'ljh',
                type: 'text',
                width: 80
            },

            {
                data: 'mc',
                type: 'text',
                width: 80
            },
            {
                data: 'sl',
                type: 'numeric',
                // numericFormat: {
                //   pattern: '0.00%'
                // },
                width: 20
            },

            {
                data: 'kc',
                type: 'text',
                width: 80
            },
            {
                data: 'bz',
                type: 'text',
                width: 80
            },
        ],
        stretchH: 'all',
        // width: 800,
        autoWrapRow: true, //自动换行
        height: 300,
        // maxRows: 22,
        manualRowResize: true,
        manualColumnResize: true,
        rowHeaders: true,//行表头
        colHeaders: ['工位','图号','名称','数量','库存处理意见','备注'],////自定义列表头
        // manualRowMove: true,//打开手动行移动
        manualColumnMove: false,
        contextMenu: true,//右键菜单展示
        filters: false,
        dropdownMenu: true,
        fillHandle:true,//允许拖动复制
        copyable: true,//右键菜单展示
        language: 'zh-CN',
        startCols: 6,//起始列数  数据data为null有效
        startRows: 6,//起始行数
        minRows: 1, //最小行列
        minCols: 0
    };
    var hotSettings1 = {
        data:data1,
        columns: [
            {
                data: 'gw',
                type: 'text',
                width: 20
            },
            {
                data: 'ljh',
                type: 'text',
                width: 80
            },

            {
                data: 'mc',
                type: 'text',
                width: 80
            },
            {
                data: 'sl',
                type: 'numeric',
                // numericFormat: {
                //   pattern: '0.00%'
                // },
                width: 20
            },

            {
                data: 'kc',
                type: 'text',
                width: 80
            },
            {
                data: 'bz',
                type: 'text',
                width: 80
            },
        ],
        stretchH: 'all',
        // width: 800,
        autoWrapRow: true, //自动换行
        height: 300,
        // maxRows: 22,
        manualRowResize: true,
        manualColumnResize: true,
        rowHeaders: true,//行表头
        colHeaders: ['工位','图号','名称','数量','库存处理意见','备注'],////自定义列表头
        // manualRowMove: true,//打开手动行移动
        manualColumnMove: false,
        contextMenu: true,//右键菜单展示
        filters: false,
        dropdownMenu: true,
        fillHandle:true,//允许拖动复制
        copyable: true,//右键菜单展示
        language: 'zh-CN',
        startCols: 6,//起始列数  数据data为null有效
        startRows: 6,//起始行数
        minRows: 1, //最小行列
        minCols: 0
    };
    var addhot = new Handsontable(addContainer, hotSettings);
    var delhot = new Handsontable(delContainer, hotSettings1);



    function clearD(){
        addhot.clear()
    }

    function getString( objarr ){
        var typeNO = objarr.length;
        var tree = "[";
        for (var i = 0 ;i < typeNO ; i++){
            if(objarr[i][0] + objarr[i][1] + objarr[i][2] + objarr[i][3] + objarr[i][4] + objarr[i][5]!=''){
                tree += "[";
                tree +="'"+ objarr[i][0]+"',";
                tree +="'"+ objarr[i][1]+"',";
                tree +="'"+ objarr[i][2]+"',";
                tree +="'"+ objarr[i][3]+"',";
                tree +="'"+ objarr[i][4]+"',";
                tree +="'"+ objarr[i][5]+"'";
                tree += "]";
                if(i<typeNO-1){
                    tree+=",";
                }
            }

        }
        tree+="]";
        return tree;
    }
    function publish_lsggd() {

        // 先格式化增加减少数据
        var addData = JSON.stringify(addhot.getSourceData());
        var delData = JSON.stringify(delhot.getSourceData());

        var isValid = $('#add_lsggd_form').form('validate');
        if (!isValid) {
            $.messager.alert('警告', '请输入必要的更改单信息！');
        } else {


            $('#add_lsggd_form').form('submit', {
                url: APP + '/Home/Lsggd/edit',
                onSubmit: function (param) {   //param为保存或者发布
                    param.id = "<?php echo ($data['id']); ?>";
                    param.addData = addData;
                    param.delData = delData;
                    param.status = 'publish';


                    // param.header = $('#add_rwh_show').textbox('getText');
                },
                success: function (data) {
                    data = $.parseJSON(data);

                    if (data.status == 1) {
                        $.messager.confirm('确认', '发布成功，您想要返回列表页面吗？', function (r) {
                            if (r) {
                                var tab = $('#tab').tabs('getSelected');
                                //encodeURI() 函数可把字符串作为 URI 进行编码
                                tab.panel('refresh', '/solve/index.php/Home/Lsggd/showEditor');
                            }
                        });
                    } else {
                        $.messager.alert('失败', data.msg, 'info');


                    }

                }
            });


        }

    }
    /**
     * [submit_zds 保存或者发布作业指导书]
     * @param  {[type]} para [0或者1，保存或者发布]
     * @return {[type]}      [description]
     */
    function submit_lsggd() {

        // 先格式化增加减少数据
        var addData=JSON.stringify(addhot.getSourceData());
        var delData=JSON.stringify(delhot.getSourceData());

        var isValid = $('#add_lsggd_form').form('validate');
        if (!isValid) {
            $.messager.alert('警告', '请输入必要的更改单信息！');
        } else {


                $('#add_lsggd_form').form('submit', {
                    url: APP+'/Home/Lsggd/add',
                    onSubmit: function (param) {   //param为保存或者发布
                        param.addData=addData;
                        param.delData=delData;



                        // param.header=$('#add_rwh_show').textbox('getText');
                    },
                    success: function (data) {
                        data = $.parseJSON(data);

                        if (data.status == 1) {
                                    $.messager.confirm('确认', '保存成功，您想要返回列表页面吗？', function (r) {
                                        if (r) {
                                            var tab = $('#tab').tabs('getSelected');
                                            //encodeURI() 函数可把字符串作为 URI 进行编码

                                                tab.panel('refresh', '/solve/index.php/Home/Lsggd/showEditor');


                                        }
                                    });
                        } else {
                            $.messager.alert('失败', data.msg, 'info');


                        }

                    }
                });


        }

    }




    $('#add_ffdw').combogrid({

        panelWidth: 450,
        idField: 'dwname',
        textField: 'dwname',
        multiple: true,
        delay: 500,
        mode: 'remote',
        striped: true,
        url: APP + '/Home/Word/ffdwList',
        columns: [[
            {field: 'dwname', title: '单位', width: 120},
            {
                field: 'fzr', title: '负责人', width: 300,
                formatter: function (value, row, index) {
                    // console.log(value);
                    var str = "";
                    if (value.length != 0) {
                        var data = $.parseJSON(value);

                        for (var i = 0; i < data.length; i++) {
                            str = str + data[i].name + '(' + data[i].email + ')';
                            if (i != data.length - 1) {
                                str = str + ',';
                            }
                        }


                    } else {
                        str = "";
                    }
                    return str;

                }
            }
        ]],
        fitColumns: false
    });

    function Search() {
        var name = decodeURIComponent($('input[name="rwh"]').val());
        $('#add_rwh').combogrid("grid").url = '请求的url';
        $('#add_rwh').combogrid("grid").datagrid("reload", { zwh: name });

    };

    function loadAgain() {
        $('#add_rwh').combogrid("grid").datagrid('reload', { zwh: '' });
        // $('#add_rwh').combogrid("grid").datagrid('clearSelections');
    }

    $('#add_rwh').combogrid({

        panelWidth: 550,
        panelHeight: 370,
        editable: false,
        idField: 'zwh',
        textField: 'zwh',
        multiple: true,
        delay: 500,

        mode: 'remote',
        pageSize : 10,
        pageList : [ 10, 15, 30, 40, 50, 100, 200 ,500,1000],
        striped: true,
        pagination: true,
        url: APP + '/Home/Mes/read',

        toolbar:'#myToolbar',
        columns: [[
            {field: 'zwh', title: '任务号', width: 310},
            {
                field: 'sjjhh', title: '计生号', width: 180
            },
            {
                field: 'lsh', title: '流水号', hidden : 'true'
            },
            {
                field: 'lshqj', title: '流水号', width: 180
            },{
                field : 'sl',
                title : '数量',
                width : 50,
                align : 'left'

            },{
                field : 'cjpz',
                title : '车型及配置',
                width : 110,
                align : 'left'

            }
        ]],
        onChange:function(newValue, oldValue){
            // 清空显示文本框
            $('#add_rwh_show').textbox('clear');
            $('#ggd_header').val('');
            var str=new Array();
            var str1=new Array();

            var g = $('#add_rwh').combogrid('grid');	// 获取数据表格对象
            var allRows = g.datagrid('getSelections');	// 获取所有被选中的行

            for(var i=0;i<allRows.length;i++){
                var jhms=allRows[i].cjpz;

                var cx=jhms.match(/^\w*/);
                // str[i]=allRows[i].zwh+' '+allRows[i].sjjhh+'（'+allRows[i].lshqj+'）'+'  '+allRows[i].sl+'辆'+cx+'\n';
                str[i]=allRows[i].sjjhh+'-'+allRows[i].sl+'辆'+cx+'（'+allRows[i].zwh+'（'+allRows[i].lshqj+'））';
                str1[i]=allRows[i].sjjhh+'-'+allRows[i].sl+'辆'+cx;
            }


// console.log(str);
            $('#ggd_header').val(str.join(',fjp203,'));
            $('#add_rwh_show').textbox('setText',str.join('\n'));
$('#ggd_title').val(str1.join(',')+'的更改单');




        },
        // keyHandler: {
        //     up: function () {
        //     },
        //     down: function () {
        //     },
        //     enter: function () {
        //     },
        //     query: function (q) {
        //         //动态搜索
        //         $('#add_rwh').combogrid("grid").datagrid("reload", {'zwh': q});
        //         $('#add_rwh').combogrid("setValue", q);
        //     }
        // },

            fitColumns: false
    });
    function go_back_lsggd(){
        var tab = $('#tab').tabs('getSelected');
        $.messager.confirm('确认','返回前需要保存吗？',function(r){
            if (r){

                // 将保存重写一次
                var addData=JSON.stringify(addhot.getSourceData());
                var delData=JSON.stringify(delhot.getSourceData());

                var isValid = $('#add_lsggd_form').form('validate');
                if (!isValid) {
                    $.messager.alert('警告', '请输入必要的更改单信息！');
                } else {


                    $('#add_lsggd_form').form('submit', {
                        url: APP+'/Home/Lsggd/add',
                        onSubmit: function (param) {   //param为保存或者发布
                            param.addData=addData;
                            param.delData=delData;
                        },
                        success: function (data) {
                            // data = $.parseJSON(data);

                            if (data.status == 1) {
                                tab.panel('refresh', '/solve/index.php/Home/Lsggd/showEditor');
                            } else {
                                $.messager.alert('保存失败', data.msg, 'info');


                            }

                        }
                    });


                }

            }else{
                tab.panel('refresh', '/solve/index.php/Home/Lsggd/showEditor');
            }

        });



//encodeURI() 函数可把字符串作为 URI 进行编码

    }
</script>